import { md5 } from 'js-md5'
import { randomString } from '@/utils'

export const summaryToMind = (item: any, home: boolean = false) => {
  let text: string
  if (home) {
    text = `<p><strong style="font-size: 14px; font-family: 微软雅黑, Microsoft YaHei; color: rgb(255, 255, 255);">${item.Title}</strong></p>`
  } else {
    text = `<p><span style="font-size: 14px; font-family: 微软雅黑, Microsoft YaHei; color: rgb(86, 86, 86);">${item.Title}</span></p>`
  }
  const node =  {
    data: {
      expand: true,
      isActive: false,
      richText: true,
      text: text,
      uid: md5(randomString(20))
    },
    children: []
  }
  if (item.Topic && item.Topic.length) {
    node.children = item.Topic.map((topic: any) => {
      return summaryToMind(topic)
    })
  }
  return node
}